package com.pf.utils;

import com.pf.dto.ResultResp;
import com.pf.enums.ResultRespEnum;

/**
 * @author PanFei
 * @version 1.0.0
 * @createTime 2022/10/16 15:39
 */
public class ResultRespUtils {

    /**
     * 调用成功
     *
     * @param message
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResultResp<T> success(String message, T data) {
        ResultResp returnResp = new ResultResp();
        returnResp.setSuccess(true);
        returnResp.setCode(ResultRespEnum.SUCCESS.getCode());
        returnResp.setMessage(message);
        returnResp.setData(data);
        return returnResp;
    }

    /**
     * 调用成功
     *
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResultResp success(T data) {
        return success(ResultRespEnum.SUCCESS.getMessage(), data);
    }

    /**
     * 调用成功
     *
     * @return
     */
    public static ResultResp success() {
        return success(ResultRespEnum.SUCCESS.getMessage(), null);
    }

    /**
     * 调用失败
     *
     * @param code
     * @param message
     * @param data
     * @param <T>
     * @return
     */
    public static <T> ResultResp<T> fail(Integer code, String message, T data) {
        ResultResp returnResp = new ResultResp();
        returnResp.setSuccess(false);
        returnResp.setCode(code);
        returnResp.setMessage(message);
        returnResp.setData(data);
        return returnResp;
    }

    /**
     * 调用失败
     *
     * @param code
     * @param message
     * @return
     */
    public static ResultResp fail(Integer code, String message) {
        return fail(code, message, null);
    }

    /**
     * 调用失败
     *
     * @param resultResp
     * @return
     */
    public static ResultResp fail(ResultRespEnum resultResp) {
        return fail(resultResp.getCode(), resultResp.getMessage(), null);
    }
}
